//
//  ShopCollectionViewCell.m
//  Products_B
//
//  Created by lanou on 16/5/30.
//  Copyright © 2016年 朋学友. All rights reserved.
//

#import "ShopCollectionViewCell.h"

@interface ShopCollectionViewCell() {
    UIImageView *_backImageView;
    UILabel *_nameLabel;
    UILabel *_salesLabel;
    UILabel *_postLabel;
    UILabel *_priceLabel;
    UILabel *_streetPriceLabel;
}

@end

@implementation ShopCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        _backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kWidth / 2 - 7.5, kWidth/ 2 - 7.5)];
        [self.contentView addSubview:_backImageView];
        
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, _backImageView.frame.origin.y + _backImageView.frame.size.height + 5, _backImageView.frame.size.width - 10, 40)];
        _nameLabel.numberOfLines = 0;
        _nameLabel.font = [UIFont systemFontOfSize:12];
        _nameLabel.alpha = 0.8;
        [self.contentView addSubview:_nameLabel];
        
        _salesLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, _nameLabel.frame.origin.y + _nameLabel.frame.size.height + 5, _backImageView.frame.size.width / 2, 20)];
        _salesLabel.alpha = 0.3;
        _salesLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_salesLabel];
        
        _postLabel = [[UILabel alloc] initWithFrame:CGRectMake(_salesLabel.frame.origin.x + _salesLabel.frame.size.width + 10, _salesLabel.frame.origin.y, _salesLabel.frame.size.width, 20)];
        _postLabel.alpha = 0.3;
        _postLabel.font = _salesLabel.font;
        [self.contentView addSubview:_postLabel];
        
        _priceLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, _salesLabel.frame.origin.y + _salesLabel.frame.size.height + 5, _backImageView.frame.size.width / 3, 30)];
        _priceLabel.textColor = [UIColor redColor];
        [self.contentView addSubview:_priceLabel];
        
        _streetPriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(_priceLabel.frame.origin.x + _priceLabel.frame.size.width + 5, _priceLabel.frame.origin.y, _backImageView.frame.size.width - _priceLabel.frame.origin.x - _priceLabel.frame.size.width - 5, 30)];
        _streetPriceLabel.alpha = 0.5;
        _streetPriceLabel.font = _salesLabel.font;
        [self.contentView addSubview:_streetPriceLabel];
        
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(_streetPriceLabel.frame.origin. x, _streetPriceLabel.frame.origin.y + _streetPriceLabel.frame.size.height / 2, 50, 1)];
        view.backgroundColor = [UIColor grayColor];
        view.alpha = 0.8;
        [self.contentView addSubview:view];
        
    }
    return self;
}

- (void)setShopModel:(ShopModel *)shopModel {
    _shopModel = shopModel;
    [_backImageView sd_setImageWithURL:[NSURL URLWithString:shopModel.backgroundImage]];
    _nameLabel.text = shopModel.name;
    _salesLabel.text = [NSString stringWithFormat:@"已售: %2ld",(long)shopModel.sales];
    if (shopModel.postage == 0) {
        _postLabel.text = @"包邮";
    } else {
        _postLabel.text = [NSString stringWithFormat:@"运费:%ld",shopModel.postage];
    }
    _priceLabel.text = [NSString stringWithFormat:@"￥%ld",shopModel.price];
    _streetPriceLabel.text = [NSString stringWithFormat:@"原价:%.2ld",shopModel.streetPrice];
}

@end





